#include "alter.h"
#include "ui_alter.h"

alter::alter(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::alter)
{
    ui->setupUi(this);
    setFixedSize(363,167);
}

alter::~alter()
{
    delete ui;
}

void alter::set_number(QString b)
{
    number=b;
}

void alter::set_type(int a)
{
    type=a;
}

void alter::on_pushButton_clicked()  //ok按钮点击时触发
{
    QString new_p = ui->textEdit->toPlainText();  //获取文本框内容
    QSqlQuery squry;
    if(type==0)  //学生用户请求修改密码
    {
        squry.exec("update student set password='"+new_p+"' where sno='"+number+"'");
        QMessageBox::about(NULL,"tip","update successful!");
    }
    else if(type==1)  //教师/管理员用户请求修改密码
    {
        squry.exec("update teacher set password='"+new_p+"' where tno='"+number+"'");
        QMessageBox::about(NULL,"tip","update successful!");
    }
    ui->textEdit->setText("");  //将文本框清空

}


void alter::on_pushButton_2_clicked() //back按钮点击时触发
{
    this->close();
}
